Skip to main content

Getting Started with Agentkit on Flow

Agentkit is an ecosystem-agnostic modular developer toolkit that lets you rapidly build, deploy, and iterate on AI agents using pre-configured environments and ready-to-use templates.

In this guide, you'll set up your own custom agent running on Flow's EVM-compatible testnet, powered by Langchain and Anthropic's Claude LLM.


Quickstart - Starting From Scratch

Open your terminal and run:


_10
npm create onchain-agent@latest

Follow the interactive setup:

  1. Type y to proceed, then press Enter.
  2. Select your framework: Langchain
  3. Choose your network: EVM
  4. Set the custom Chain ID:
    • 545 for Flow Testnet
    • 747 for Flow Mainnet
  5. JSON-RPC endpoint:

    _10
    https://testnet.evm.nodes.onflow.org


Project Setup

Once your scaffold is ready:


_10
cd onchain-agent
_10
npm install

Now open the project in your preferred IDE (e.g. Cursor).

Environment Configuration

  1. Create a .env.local file (or edit the one generated).
  2. Add your API keys (we'll use Anthropic here).

You can also use OpenAI, DeepSeek, or any other supported LLM.

Get Your Anthropic API Key

  • Head to Anthropic Console
  • Create an account and purchase credits
  • Click Create Key, name it, and copy the API key
  • Add this to your .env.local:

_10
ANTHROPIC_API_KEY=your_api_key_here

Wallet Setup with MetaMask

  1. Add Flow Testnet to MetaMask
  2. Use the Faucet to fund your wallet
  3. Get your private key:
    • Click the ... menu in MetaMask > Account Details
    • Enter your password, copy the private key
  4. Add it to .env.local:

_10
PRIVATE_KEY=your_private_key_here

Your .env.local should look something like this:


_10
PRIVATE_KEY=...
_10
ANTHROPIC_API_KEY=...

Now run:


_10
mv .env.local .env
_10
npm run dev

Visit your local server:


_10
http://localhost:3000


Configure Your LLM

If your agent doesn't respond yet — no worries! You still need to configure your LLM and client libraries.

Choose a Model

Langchain supports many LLMs (full list here).

For this example, we'll use Anthropic's claude-3-5-haiku-20241022, a lightweight and affordable model. Alternatively, DeepSeek is highly recommended for budget-friendly usage.

Update create-agent.ts

Change the default model from OpenAI:


_10
const llm = new ChatOpenAI({ model: "gpt-4o-mini" });

To Anthropic:


_10
import { ChatAnthropic } from "@langchain/anthropic";
_10
_10
const llm = new ChatAnthropic({ model: "claude-3-5-haiku-20241022" });

Install the package:


_10
npm install @langchain/anthropic


Configure Flow and Viem Wallet

Update the Faucet Provider Logic

Change this:


_10
const canUseFaucet = walletProvider.getNetwork().networkId == "base-sepolia";

To:


_10
const canUseFaucet = walletProvider.getNetwork().networkId == "flow-testnet";

Add Flow Context Message to Agent

This gives your agent context about the Flow testnet:


_14
const flowContextMessage = canUseFaucet ? `
_14
You are now operating on the Flow blockchain testnet using a Viem wallet. Flow is a fast, decentralized, and
_14
developer-friendly blockchain designed for NFTs, games, and apps.
_14
_14
Key facts about Flow:
_14
- Flow uses a proof-of-stake consensus mechanism
_14
- The native token is FLOW
_14
- Flow has a unique multi-role architecture for high throughput
_14
- The testnet is EVM-compatible (works with MetaMask + Viem)
_14
- RPC URL: https://testnet.evm.nodes.onflow.org
_14
- Chain ID: 545
_14
_14
Your wallet address is \${await walletProvider.getAddress()}.
_14
` : '';

Then inject it into the agent message modifier:


_16
agent = createReactAgent({
_16
llm,
_16
tools,
_16
checkpointSaver: memory,
_16
messageModifier: `
_16
You are a helpful agent interacting with the Flow blockchain testnet using a Viem wallet.
_16
Flow testnet supports EVM, so you can use Ethereum-compatible tools.
_16
\${flowContextMessage}
_16
_16
Before your first action, check the wallet details. If you see a 5XX error, ask the user to try again later.
_16
If a task is unsupported, let the user know and point them to CDP SDK + Agentkit at:
_16
https://docs.cdp.coinbase.com or https://developers.flow.com.
_16
_16
Be concise, helpful, and avoid repeating tool descriptions unless asked.
_16
`,
_16
});


You're Done!

You now have a working AI agent connected to Flow testnet using Agentkit!

You can send faucet tokens to your wallet and start testing smart contract interactions or on-chain workflows.


Starter Project

Want to skip the setup?

Fork the Flow Agentkit Starter

This starter includes all necessary config to start building immediately on Flow.


Adding AgentKit to an Existing Project

Already have a project and want to add AgentKit? Follow these steps to integrate it into your existing codebase:

Install the Package

Run this command in your project's root directory:


_10
npm install onchain-agent@latest

This will:

  • Download and install the latest version of the onchain-agent package
  • Add it to the dependencies section of your package.json
  • Update your node_modules folder accordingly

Configure Environment

  1. Create or update your .env file with the necessary API keys:

_10
PRIVATE_KEY=your_wallet_private_key
_10
ANTHROPIC_API_KEY=your_anthropic_api_key
_10
# Or other LLM API keys

  1. Configure your RPC endpoints for Flow:

_10
FLOW_TESTNET_RPC_URL=https://testnet.evm.nodes.onflow.org
_10
FLOW_MAINNET_RPC_URL=https://mainnet.evm.nodes.onflow.org

Integrate AgentKit in Your Code

Import and configure AgentKit in your application:


_35
// Import AgentKit components
_35
import {
_35
createReactAgent,
_35
ChatAnthropic
_35
} from 'onchain-agent';
_35
import {
_35
createWalletClient,
_35
http,
_35
createPublicClient
_35
} from 'viem';
_35
_35
// Set up your Flow wallet provider
_35
const walletClient = createWalletClient({
_35
transport: http('https://testnet.evm.nodes.onflow.org'),
_35
chain: {
_35
id: 545, // Flow Testnet
_35
name: 'Flow Testnet',
_35
},
_35
account: yourPrivateKey
_35
});
_35
_35
// Configure the LLM
_35
const llm = new ChatAnthropic({
_35
model: "claude-3-5-haiku-20241022"
_35
});
_35
_35
// Create your agent
_35
const agent = createReactAgent({
_35
llm,
_35
tools: yourSelectedTools,
_35
// Additional configuration
_35
});
_35
_35
// Use the agent in your application
_35
// ...

Add Specialized Tools (Optional)

To add specialized blockchain tools to your agent:


_22
import {
_22
viem,
_22
ViemToolConfig
_22
} from 'onchain-agent';
_22
_22
// Configure Viem tools for Flow
_22
const viemTools = viem.createTools({
_22
chain: {
_22
id: 545,
_22
name: 'Flow Testnet',
_22
},
_22
transport: http('https://testnet.evm.nodes.onflow.org')
_22
} as ViemToolConfig);
_22
_22
// Add these tools to your agent
_22
const agent = createReactAgent({
_22
llm,
_22
tools: [
_22
...viemTools,
_22
// Other tools
_22
],
_22
});


Resources


Happy hacking on Flow!